package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.dao.ArticleDao;
import com.itany.entity.Article;
import com.itany.service.ArticleService;
import com.itany.service.UserService;
import com.itany.vo.ResponseResult;
import org.apache.tools.ant.types.CommandlineJava;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2019/12/20 14:53
 * Describe:
 * version:1.0
 */

@RestController
@RequestMapping("/articles")
public class ArticleController {


    @Autowired
    ArticleService articleService;

    @RequestMapping("/findByPage")
    public Map findByPage(Integer page, Integer rows, String title, String type, String mode){
        PageInfo info  =articleService.findByPage(page,rows, title, type, mode);

        System.out.println("----------ArticleController-----------");
        System.out.println(title+ "-"+ type+"-"+mode);
        System.out.println(info.getList());
        Map map = new HashMap();
        map.put("total", info.getTotal());
        map.put("rows",info.getList());

        return map;
    }

    @RequestMapping("/findAll")
    public List<Article> findAll(){
        List<Article> articles = articleService.findAll();
        return articles;
    }


    // 为什么方法参数改为map就报找不到方法错误！！！
    // @RequestMapping("/findByPage")
    // public Map findByPage(Map map){
    //     String title = (String) map.get("title");
    //     String type = (String) map.get("type");
    //     String mode = (String) map.get("mode");
    //     System.out.println(map.get("page"));
    //     System.out.println(map.get("rows"));
    //     // Integer rows = Integer.parseInt(map.get("rows"));
    //
    //     // PageInfo info  =articleService.findByPage(page,rows);
    //     // System.out.println("----------ArticleController-----------");
    //     // System.out.println(page+"-"+mode);
    //     // System.out.println(title+ "-"+ type+"-"+mode);
    //     // System.out.println(info.getList());
    //     Map tmp  = new HashMap();
    //     // tmp.put("total", info.getTotal());
    //     // tmp.put("rows",info.getList());
    //
    //     return map;
    // }


}
